package com.project.internship.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Audit;
import com.project.internship.mapper.AllotMapper;
import com.project.internship.mapper.AuditMapper;
import com.project.internship.service.AuditService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.internship.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2020-04-20
 */
@Service
public class AuditServiceImpl extends ServiceImpl<AuditMapper, Audit> implements AuditService {

    @Autowired
    AuditMapper auditMapper;

    @Override
    public Integer addDeclare(Audit audit) {
        audit.setDepartmentName(UserUtils.getCurrentUser().getName());
        return auditMapper.insert(audit);
    }

    @Override
    public IPage<Audit> getDeclare(Page<Audit> page, String keyword) {
        String name = UserUtils.getCurrentUser().getName();
        return auditMapper.getDeclare(page, name, keyword);
    }

    @Override
    public IPage<Audit> getAudit(Page<Audit> page, Integer status, String keyword) {
        return auditMapper.getAudit(page, status, keyword);
    }

    @Override
    public Integer setAuditSuccess(Audit audit) {
        audit.setStatus(1);//通过
        return auditMapper.updateById(audit);
    }

    @Override
    public Integer setAuditFail(Audit audit) {
        audit.setStatus(2);//未通过
        return auditMapper.updateById(audit);
    }
}
